package jmir.oscar.panell.figures;

public class Rectangle extends Figura2D {
	private final double costatVertical;
	private final double costatHoritzontal;
	
	// Constructor en el que li pases el costat horitzontal i vertical
	public Rectangle(int coordenadaX, int coordenadaY, double i, double j, Color colorBorde, Color colorFondo, int anchoBorde) {
		super(coordenadaX, coordenadaY, colorBorde, colorFondo, anchoBorde);
		this.costatHoritzontal = i;
		this.costatVertical = j;
	}
	
	public Rectangle(Color colorFondo, Color colorBorde, int anchoBorde, double costatVertical, double costatHoritzontal) {
		super(colorFondo, colorBorde, anchoBorde);
		this.costatVertical = costatVertical;
		this.costatHoritzontal = costatHoritzontal;
	}
	
	public Rectangle(double costatVertical, double costatHoritzontal) {
		super();
		this.costatVertical = costatVertical;
		this.costatHoritzontal = costatHoritzontal;
	}
		
	public double getCostatVertical() {
		return costatVertical;
	}
	
	public double getCostatHoritzontal() {
		return costatHoritzontal;
	}
	
	@Override
	public double calculaPerimetre() {
		double perimetre;
		perimetre = getCostatHoritzontal()*2 + getCostatVertical()*2;
		return perimetre;
	}
	
	@Override
	public double calculaSuperficie() {
		double superficie;
		superficie = getCostatHoritzontal()*getCostatVertical();
		return superficie;
	}
	
	
	@Override
	public String toString() {
		return "Rectangle [costatVertical=" + costatVertical
				+ ", costatHoritzontal=" + costatHoritzontal + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(costatHoritzontal);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(costatVertical);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Rectangle))
			return false;
		Rectangle other = (Rectangle) obj;
		if (Double.doubleToLongBits(costatHoritzontal) != Double
				.doubleToLongBits(other.costatHoritzontal))
			return false;
		if (Double.doubleToLongBits(costatVertical) != Double
				.doubleToLongBits(other.costatVertical))
			return false;
		return true;
	}
	
	
}
